/**
 * 项目名称:
 *
 * @Author: 夏国倩
 * @Date: 2023/10/11 10:12
 * @Copyright
 */
package IO2;

import java.io.FileNotFoundException;
import java.io.FileOutputStream;
import java.io.PrintStream;
import java.text.SimpleDateFormat;
import java.util.Date;

//记录日志的方法
public class Logger {
    public static void log(String msg) {
        try {
            PrintStream out=new PrintStream(new FileOutputStream("log"));
            //改变输出方向
            System.out.println(out);
            //日期当前时间
            Date nowTime=new Date();
            SimpleDateFormat sdf=new SimpleDateFormat("yyyy-MM-dd HH:mm:ss SSS");
            String strTime=sdf.format(nowTime);
            System.out.println(strTime+":"+msg);
        } catch (FileNotFoundException e) {
            throw new RuntimeException(e);
        }
    }
}
